% Notes for Hacker Within Software Carpentry Bootcamp, Day 1
% January 12, 2009

\documentclass{article}
\usepackage[usenames]{color}
\usepackage[
naturalnames = true, 
colorlinks = true, 
linkcolor = Black,
anchorcolor = Black,
citecolor = Black,
menucolor = Black,
urlcolor = Blue
]{hyperref}

\title{Software Carpentry Bootcamp}
\author{The Hacker Within
\\ \href{mailto:hacker.within.admin@gmail.com}{\texttt{hacker.within.admin@gmail.com}}
\\ \url{http://groups.google.com/group/hacker-within/}
\\ \url{http://code.google.com/p/hacker-within/}}
\date{Day 1 -- January 12, 2009}

\setlength{\parindent}{0em}

\begin{document}
\maketitle

\section{Welcome}

Welcome to Software Carpentry Bootcamp. This training course will be taught by members of The Hacker Within, a scientific computing interest group based in the Engineering Physics Department but open to anyone. In short, the purpose of The Hacker Within is to help you be a more productive and efficient researcher and student---and to put you in contact with others trying to do likewise. \medskip

To sign up for \href{http://groups.google.com/group/hacker-within}{our Google Group} (includes an email mailing list), visit it and click ``Apply for group membership'' or \href{mailto:hacker.within.admin@gmail.com}{\texttt{email us}}. \medskip

We'll start today's session by introducing the instructors (Milad Fatenejad, Katy Huff, Ahmad Ibrahim, Kyle Oliver, and Matt Terry) and distributing temporary CAE user names and passwords.

\subsection{Remarks on today's session}
Please note that we've tried to make this training as accessible to the inexperienced Unix user as possible while still getting to some fairly sophisticated and research-applicable material by Days 2 -- 3. If you're not totally new to the command line, please bear with us and know that we've taken considerable pains to try to restrict our ``Unix basics''-type material to the absolute essentials of what you need to know to dive into some legitimate software carpentry. If you want to work only on your Unix fluency, we suggest you try the DoiT \href{http://www.doit.wisc.edu/training/student/index.aspx}{Software Training for Students} (STS) classes called ``Linux 1'' and ``Linux 2.'' \medskip

Speaking of Unix/Linux, we'll use the terms more or less interchangeably here. Technically the CAE machines we're working on today run a Linux distribution, but that shouldn't matter much for the kinds of things we're doing.

\subsection{Getting these notes}

Our first order of business is to get you access to these notes and other course materials. We've placed them in a repository on our \href{http://code.google.com/p/hacker-within/}{Google Code site}. However, instead of having you visit the site and download them manually, we'll use this as an opportunity to introduce the Unix command shell and a few useful shell commands and programs.

\section{Navigating the shell}
From the \textsc{WikipediA} article ``Shell (computing)'':
\begin{quote}
In computing, a shell is a piece of software that provides an interface for users. Typically, the term refers to an operating system shell which provides access to the services of a kernel. The name `shell' originates from shells being an outer layer of interface between the user and the innards of the operating system (the kernel).
\end{quote}
You can access the command shell by opening a new \texttt{terminal} using the second icon on the menu bar at the bottom of your screen. When you open a \texttt{terminal}, an interactive shell program will open. Two popular shells are \texttt{bash} and \texttt{tcsh}. Since CAE uses tcsh as its default, so will we. The shell's \textit{command line} is how you run commands and navigate through the file system(s) your computer is connected to. The command line is also sometimes called the prompt, and it's often denoted with a greater-than sign (\verb|>|) that points to where your cursor is ready to enter input.

\subsection{Unix paths and \texttt{pwd}}
A Unix filespace is made up of many nested directories (folders), just as in other operating systems. In Unix parlance, the location of each directory (and the files inside them) is given by a ``path.'' Paths can be absolute (start with \texttt{/}) or relative (start with \texttt{.}, \texttt{..}, etc.). You can always print out the full absolute path of the directory you're currently working in with the command \texttt{pwd} (Print Working Directory). Here's an example from the directory this file was written in:
\begin{verbatim}
~/hacker-within/bootcamp/monday> pwd
/pong/usr4/k/kmoliver/hacker-within/bootcamp/monday
\end{verbatim}
In this example, we can see that the command prompt gives an abbreviated path name before the greater-than sign, replacing all the directories up to and including \verb|kmoliver/| with a single character. In the next section, we'll see why.

\subsection{Home directory ($\sim$)}
The shell starts your session from a special directory called your \textit{home directory}. The tilde ($\sim$) character can be used as a shortcut to your home directory. Thus, when you log in, you probably see the command prompt telling you you're in your home directory:
\begin{verbatim}
~>
\end{verbatim}
Returning to the previous example, we see that the home directory is everything up to and including \verb|kmoliver/|. However, because $\sim$ is an abbreviation for a string that begins with \texttt{/}, we see that \verb|~/current-directory| is still an absolute path.

\subsection{Printing directory contents (\texttt{ls})}
The command \texttt{ls} allows you to print out a list of all the files and sub-directories in the directory you're currently in. Here's a sample \texttt{ls} call and output from a directory called \texttt{current-directory}, which is itself located in the user's home directory:
\begin{verbatim}
~/current-directory> ls
file1.txt  file2.txt  file3.txt  sub-directory/
\end{verbatim}
You can see that there are three files and one sub-directory; directories always get marked with a forward slash (\texttt{/}).

\subsection{Changing directories (\texttt{cd})}

You can change directories with the \texttt{cd} command. When you type only those letters, the \texttt{cd} command assumes you want to go to your home directory, so that's where it takes you:
\begin{verbatim}
~/hacker-within/bootcamp/monday> cd
~>
\end{verbatim}
However, the \texttt{cd} command can also take one \textit{argument}. If you add a space and then enter the path to the directory you want to move to, the shell takes you there. The argument can be an absolute or relative path name, and if the directory you want to change to is inside your current directory, you can drop everything up to and including the current directory's name:
\begin{verbatim}
~/hacker-within/bootcamp/monday> cd
~> cd hacker-within/bootcamp/monday/
~/hacker-within/bootcamp/monday> cd ~/hacker-within/
~/hacker-within> cd /pong/usr4/k/kmoliver/hacker-within/bootcamp/
~/hacker-within/bootcamp> cd monday
~/hacker-within/bootcamp/monday> 
\end{verbatim}
Another useful convention to be aware of is that the current directory is also represented by a single dot (.), and the current directory's parent is represented by two dots (..) when forming relative paths:
\begin{verbatim}
~/hacker-within/bootcamp/monday> cd ..
~/hacker-within/bootcamp> cd ./monday
~/hacker-within/bootcamp/monday>
\end{verbatim}

\subsection{Secure shell (\texttt{ssh})}
You can get shell access to another machine using a program called \texttt{ssh} (Secure SHell). For instance, for user ``dave'' to log on to a networked computer ``hal, '' he would use the \texttt{ssh} command with an argument specifying his username and the computer name:
\begin{verbatim}
~> ssh dave@hal
\end{verbatim}
Or, if hal is a server on the remote domain ``discoveryone.com'':
\begin{verbatim}
~> ssh dave@hal.discoveryone.com
\end{verbatim}
Just as you can use ssh to log into other computers, so can other programs.

\subsection{Preview: \texttt{svn}}
We'll talk more about this topic later in the week, but to get you the course materials, we have to spend a bit of time with Subversion, aka \texttt{svn}. Subversion is a \textit{version control system}, a piece of software originally designed to help developers collaborate on software projects. (See \href{http://hacker-within.googlegroups.com/web/version_control.pdf?gda=uRZ-RUUAAADHVUDQ3N8Yw8kHj6iyVooeMVb5SmxHms-9WEHzI9Gz5yoHXKJ_3tDHc0LZ-vto5bAcn8WIbWh5zqeDKtDBmq67Gu1iLHeqhw4ZZRj3RjJ_-A}{this link} for the notes from a past Hacker Within meeting about version control.) Source code for projects managed by Google Code are stored in \texttt{svn} repositories that can be ``checked out'' (downloaded) by anonymous users. We're going to use \texttt{svn} to check out the notes and exercises for this training. \medskip

Subversion's \texttt{checkout} routine needs two arguments: the remote location of the repository and what you want to name the parent directory for the local copy of the files you'll receive. Use the following command, preferably from your home directory:
\begin{verbatim}
~> svn checkout \
? http://hacker-within.googlecode.com/svn/trunk/bootcamp bootcamp
\end{verbatim}
(\textit{Note: When you insert a backslash at the command line, it prints a question mark and allows you to continue entering arguments as if you were still on the same line. We use the feature here as a convenience for fitting the entire command sequence on the readable part of the page.})

\subsection{Exercise: Exploring your new directories}
Using the commands we've discussed so far, explore the files you just checked out. When you understand the directory structure, try to get the hang of moving between directories that are more than one hierarchical level apart. Typing \mbox{\texttt{cd ..}} four times can get a little tedious.

\section{Running programs}

By now we've run a number of commands and programs, but it's perhaps worth stating explicitly that you run a program by typing its name followed by any arguments that may be necessary. If you're confused about what required and optional arguments exist, there's a place you can always go for help\ldots

\subsection{Using \texttt{man} pages}

The program \texttt{man} (manual) is an interface to online reference manuals. If you pass the name of a command or program to \texttt{man} as an argument, it will open the help file for that command or program:
\begin{verbatim}
NAME
       man - an interface to the on-line reference manuals

SYNOPSIS
       man  [-c|-w|-tZ]  [-H[browser]]  [-T[device]] [-adhu7V]
       [-i|-I] [-m system[,...]] [-L locale] [-p  string]  [-C
       file]  [-M  path]  [-P pager] [-r prompt] [-S list] [-e
       extension] [[section] page ...] ...
       man  -l  [-7]  [-tZ]  [-H[browser]]  [-T[device]]   [-p
       string] [-P pager] [-r prompt] file ...
       man -k [apropos options] regexp ...
       man -f [whatis options] page ...

DESCRIPTION
       man  is  the  systems manual pager. Each page argument
       given to man is normally the name of a program, utility
       or  function.   The manual page associated with each of
       these arguments is then found and displayed. A section,
       if  provided, will direct man to look only in that sec
       tion of the manual.  The default action is to search in
       all  of the available sections, following a pre-defined
       order and to show only the first page  found,  even  if
       page exists in several sections.


...etc.
\end{verbatim}
What follows \texttt{man} in the \texttt{SYNOPSIS} is a listing of the optional and required arguments. If you scroll down in the document, each one gets explained.

\subsection{Moving around in \texttt{less}}
\texttt{man} opens the help documents in a program called \texttt{less}, which you can use to look at other text files as well (just call \texttt{less filename}). There's lots to learn about \texttt{less} (use \texttt{man less} to get an overview), but the most important things to know are as follows:
\begin{enumerate}
\item Use the up and down arrows to scroll up and down.
\item Use \texttt{Page Up} and \texttt{Page Down} to move up or down by an entire page.
\item Use a forward slash (\texttt{/}) followed by a search term and then \texttt{Enter} to search for a particular word. The letter \texttt{n} (next) toggles through each occurrence.
\item Use \texttt{q} to quit.
\end{enumerate}
As you might expect, \texttt{less} is modeled on an earlier program called \texttt{more}. Ironically, \texttt{more} has fewer features, and you probably shouldn't bother with it.

\subsection{Arguments, options, and variables}
There are different ways to pass information to the command-line programs and commands you need to use. We've seen the first one: arguments. An argument simply gets added after the command. You can add multiple arguments if the command expects that behavior. We've added single arguments when we've changed into a specific directory (e.g., \texttt{cd ..}), and we added several arguments when we ran \texttt{svn}.\medskip

In fact, we can pass an argument to a program called \texttt{make} to tell it to produce and display these notes, using a couple of the files we checked out. If you change to the \texttt{bootcamp/monday} directory and type \texttt{make}, that program will call others to create a PDF version of these notes but won't display them. However, if you add the argument \texttt{view} to the call to \texttt{make}, the program does some extra work and opens that PDF as well.\medskip

\textit{Options}, also called \textit{switches} or \textit{flags}, tell the program to run in some pre-defined way. Options are usually specified with a minus sign (\texttt{-}) in front of them. For instance, if we run \texttt{man ls} and scroll down, we see that the \texttt{-r} option lists directory contents in reverse order.\medskip

\textit{Variables} can be used to pass in specific kinds of information and are usually specified with a double minus sign (typically pronounced ``minus minus''). Further perusal of the \texttt{ls man} page indicates that a variable called \texttt{sort} can be set to certain values to sort directory contents in various ways. For instance,  \texttt{--sort=time} sorts directory contents by file modification time, with the most recent file first.\medskip

\href{http://www.youtube.com/watch?v=gldlyTjXk9A}{Putting it all together}:
\begin{verbatim}
~/weaponry> ls
etc  fear  ruthless_efficiency  surprise
~/weaponry> ls -r
surprise  ruthless_efficiency  fear  etc
~/weaponry> ls -r --sort=time
fear  surprise  ruthless_efficiency  etc
\end{verbatim}

\subsection{Running programs in different directories}
We'll talk tomorrow about how the shell knows where to find the commands and programs you use at the command line. For now, suffice it to say that unless you take some initiative, you can't run just any old program on your computer from any directory. If you want to run a program in a non-standard location, you have to tell the shell exactly where that program is by invoking it with an absolute or relative Unix path.\medskip

For instance, we can use \texttt{make} again (from the \verb|bootcamp/monday/hello| directory) to build a copy of a program we'll use on Wednesday. However, after we've done so, we can still only run that program if we tell the shell exactly where it is:
\begin{verbatim}
~/hacker-within/bootcamp> hello
hello: Command not found.
~/hacker-within/bootcamp> ./monday/hello/hello
Hello, World!
~/hacker-within/bootcamp> cd monday/hello
~/hacker-within/bootcamp/monday/hello> ./hello
Hello, World!
~/hacker-within/bootcamp/monday/hello> cd
~> /pong/usr4/k/kmoliver/hacker-within/bootcamp/monday/hello/hello
Hello, World!
\end{verbatim}

\subsection{Killing or interrupting programs}
Sometimes you'll run a program and then think better of it, or---even more likely---you'll run it incorrectly and need to kill its execution. \texttt{Ctrl-c} will usually accomplish this for non-interactive programs. Interactive programs (like \texttt{less}) typically define some other keystroke for killing or exiting the program. \texttt{Ctrl-d} and \texttt{q} will sometimes do the trick in these cases. \medskip

Another common need is to momentarily \textit{interrupt} the program and then continue its execution later. \texttt{Ctrl-z} will accomplish the first part, \texttt{fg \% x} (ForeGround) the second. Here \texttt{x} is the job number of the program you interrupted, determined using the \texttt{jobs} command:
\begin{verbatim}
~/haystack> grep -r "needle" *

Suspended
~/haystack> jobs
[1]  + Suspended                     grep -r needle *
~/haystack> fg %1
grep -r needle *
\end{verbatim}

\subsection{Exercise: Learning about a command}
Take some time to explore the \texttt{man} page of a command we've discussed or of another command or program you know of. Learn about a couple new arguments or options and try them out. Practice killing or interrupting programs if necessary.

\section{Manipulating files and directories}
\subsection{Copying and renaming files (\texttt{cp} and \texttt{mv})}
Now that we've explored some files and directories, let's start learning how to create and change them. To make a copy of a file, use the \texttt{cp} command. The first required argument is the source file (the one you want to copy), as a relative or absolute path. The second is the destination file (the copy itself), as a relative or absolute path. However, if the destination is in another directory, that directory must already exist:
\begin{verbatim}
~/things>ls
thing1
~/things>cp thing1 thing2
~/things>ls
thing1  thing2
~/things>cp ./thing1 ./more_things/thing2
cp: cannot create regular file `./more_things/thing2': 
No such file or directory
\end{verbatim}
Another option if you don't need the original is to use \texttt{mv} (move), which renames the file instead of copying it. The reason the command evokes ``move'' is that if the new name is a path in another directory, the file is effectively moved there:
\begin{verbatim}
~/sam>ls
i_am_sam
~/sam>mv i_am_sam sam_i_am
~/sam>ls
sam_i_am
~/sam>mv ./sam_i_am ../sam_i_am
~/sam>cd ..
~>ls
sam/  sam_i_am
\end{verbatim}

\subsection{Making directories (\texttt{mkdir})}
You can make new directories with the \texttt{mkdir} command. Using our usual Unix path conventions, you can make then anywhere, not just in your current working directory. However, the rule about not putting a file in a non-existent directory applies to new directories too:
\begin{verbatim}
~/kingdom/phylum>mkdir class
~/kingdom/phylum>mkdir ./class/order
~/kingdom/phylum>mkdir ./class/order/family/genus
mkdir: cannot create directory `./class/order/family/genus': 
No such file or directory
\end{verbatim}

\subsection{Deleting files and directories (\texttt{rm})}
Delete files using the \texttt{rm} (remove) command. To delete directories, you need to use the \texttt{-r} (recursive) flag. This requirement prevents you from deleting entire branches of a directory tree without confirming that you do, in fact, want the shell to descend into all subdirectories of the given directory and delete them all and their contents.\medskip

\subsection{Flags and wildcards}
In fact, flags are often important when using these file and directory manipulation commands. For instance, you can \texttt{mv} a directory without any flags, but to copy accomplish the same with with \texttt{cp}, you also need the \texttt{-r} flag:
\begin{verbatim}
~>mv zeppelin/ brits/
~>cp beatles/ brits/
cp: omitting directory `beatles/'
~>ls brits
zeppelin/
~>cp -r beatles/ brits/
~>ls brits
beatles/  zeppelin/
\end{verbatim}
An alternative to copying, moving, or removing entire directories is to use the asterisk as a wildcard character to match more than one file at once:
\begin{verbatim}
~>cp beatles/* brits/.
~>cp zeppelin/* brits/.
~>cp beatles/john* johns/.
~>cp zeppelin/john* johns/.
~>ls brits
george  jimmy  john  john_paul  paul  ringo  robert
~>ls johns
john  john_paul
\end{verbatim}
But notice that we've overwritten a ``john'' during the second copy into each directory. To help avoid making such mistakes, you can use \texttt{-i} to run the command interactively; the shell will then ask you to confirm any operations it thinks seem suspicious:
\begin{verbatim}
~>cp beatles/john* johns/.
~>cp -i beatles/john* johns/.
cp: overwrite `johns/./john'? y
\end{verbatim}
In a sense, the opposite of \texttt{-i} is \texttt{-f}, which forces any operations that the shell might otherwise warn you about, even if you didn't use the k\texttt{-i} flag:
\begin{verbatim}
~> mv zeppelin/john deceased/.
~> mv beatles/john deceased/.
mv: overwrite `deceased/./john'? n
~> mv -f beatles/john deceased/.
~> 
\end{verbatim}

\subsection{Links (\texttt{ln})}
The \texttt{ln} command allows you to create a hard or symbolic link to a file, effectively creating more than one reference to where the contents of the file are stored. For our purposes, symbolic links (created with \texttt{ln -s}) are the safest and most useful. Let's say, for instance, that you have a hard time remembering whether our \texttt{Hello, World!} program is called \texttt{hello} or \texttt{helloworld}. One solution is to add a symbolic link with the incorrect filename that points to the correct filename:
\begin{verbatim}
~/hacker-within/bootcamp/monday/hello% ./helloworld
./helloworld: Command not found.
~/hacker-within/bootcamp/monday/hello% ln -s hello helloworld
~/hacker-within/bootcamp/monday/hello% ls
hello*  hello.cpp*  helloworld@  Makefile*
~/hacker-within/bootcamp/monday/hello% ./helloworld
Hello, World!
\end{verbatim}
Symbolic links are also useful for providing access to large, shared resources (rather than storing multiple copies in multiple locations) or deeply nested subdirectories (say, \texttt{~/mon\_notes} instead of \texttt{~/hacker-within/bootcamp/monday}).

\subsection{Permissions}
Permissions are a subtle but important part of using and sharing files on Unix systems. This topic tends to confuse people, but the basic gist is that different people can be given different types of access to a given file. The ``different types of people'' are the individual \textit{\textbf{u}ser} who owns the file, the \textit{\textbf{g}roup} who's been granted special access to it, and all \textit{\textbf{o}thers}. The ``different types of access'' are permission to \textit{\textbf{r}ead}, \textit{\textbf{w}rite to}, or \textit{e\textbf{x}ecute} a file or directory. Finally, three commands allow you to manage permissions of your files:

\begin{enumerate}
\item \texttt{ls -l [file]} displays, among other things, the permissions for that file
\item \texttt{chown [-R] [[user]][:group] target1 [[target2 ..]]} changes the individual user and group ownership of the target(s), recursively if \texttt{-R} is used and one or more targets are directories
\item \texttt{chmod [options] mode[,mode] target1 [[target2 ...]]} changes or sets the permissions for the given targets to the given modes. 
\end{enumerate}

\subsubsection{\texttt{ls -l}}
If we run that first command on the source file for these notes, the first thing we see is a code with ten permission digits or ``bits.'' The first bit displays as a \texttt{d} if the target we're looking at is a directory, an \texttt{l} if it's a link, and generally \texttt{-} otherwise. After that, we see three sets of three bits indicating whether the user owner, group owner, and others (in that order) have read, write, or and execute privileges for that file:
\begin{verbatim}
~/hacker-within/bootcamp/monday> ls -l notes.tex
-rw-rw---- 1 kmoliver kmoliver 21073 2009-01-12 08:52 notes.tex
\end{verbatim}
You can check the \texttt{ls man} page for details on the rest of the information in this display, but the other relevant entries here are the two \texttt{kmoliver}s. The first indicates that the user \texttt{kmoliver} is the individual owner of this file. The second says that the \textit{group} \texttt{kmoliver} is the group owner of the file. In fact, if you run the command \texttt{groups}, you'll probably realize that each user is also a member of the group of the same name. Anyway, this display shows that \texttt{notes.tex} is a non-directory file that only \texttt{kmoliver} has read and write privileges for.

\subsubsection{\texttt{chown}}
To give members of the research group \texttt{cnergg} permission to also read and write to this file, I need to change its group ownership \textit{and} make sure that members of this group can navigate to it---directories that are not executable by a given user can't be navigated into, and directories that aren't readable by a given user can't be printed with \texttt{ls}. We can handle the first part of the permission-changing process with \texttt{chown}:
\begin{verbatim}
~/hacker-within/bootcamp/monday> ls -l notes.tex
-rw-rw---- 1 kmoliver kmoliver 22464 2009-01-12 09:09 notes.tex
~/hacker-within/bootcamp/monday> chown :cnergg notes.tex
~/hacker-within/bootcamp/monday> ls -l notes.tex
-rw-rw---- 1 kmoliver cnergg 22464 2009-01-12 09:09 notes.tex
\end{verbatim}

\subsubsection{chmod}
We can make sure this directory is visit- and read-able by using \texttt{chmod} in recursive mode. If I know my home directory can be visited by members of \texttt{cnergg}, then I can set the permissions on the entire directory tree under \texttt{~/hacker-within} as follows:
\begin{verbatim}
~> chown -R :cnergg hacker-within/
~> chmod -R g+rx hacker-within/
\end{verbatim}
In the \texttt{chmod} command, the mode entry \texttt{g+rx} means we \textit{add} the read and execution bits to the group's permissions for the file. There are many ways to use the mode-entry syntax to do fairly complication permission-setting operations on entire directories. The \href{http://en.wikipedia.org/wiki/Chmod}{\textsc{WikipediA} article} on \texttt{chmod} has a pretty good summary, including of an alternative convention to referring to specific permissions configurations via \href{http://en.wikipedia.org/wiki/File\_system\_permissions#Octal\_notation}{a number in octal notation}.

\subsection{More file inspection: \texttt{head/tail, grep}}
Before we move to today's final exercise, it will be helpful to know a couple new commands for file inspection. When dealing with input and output files to scientific computing codes, you often only need to see the beginning or end of a file (for instance, to check some important input parameter or see if your run completed successfully). The command \texttt{head} (\texttt{tail}) prints the first (last) ten lines of the given file:
\begin{verbatim}
~/hacker-within/bootcamp/monday% head notes.tex
% Notes for Hacker Within Software Carpentry Bootcamp, Day 1
% January 12, 2009

\documentclass{article}
\usepackage[usenames]{color}
\usepackage[
naturalnames = true,
colorlinks = true,
linkcolor = Black,
anchorcolor = Black,
~/hacker-within/bootcamp/monday% tail notes.tex
\subsection{Exercise: Organizing a mess of files}


\section{everything else}
Here's the rest of the stuff on my outline:
tar/zip/gz, lpr
file conversion
cat

\end{document}
\end{verbatim}
An even more useful command for learning something about \
the contents of a file is \texttt{grep} (the command \
etymology is a little esoteric), which is a really powerful \
text-search tool. We'll talk way more about \texttt{grep} and \
the related topic of \textit{regular expressions} on Day 3, but \
for now, simply notes that \texttt{grep ``word'' files} searches \
for ``word'' in files and prints out the lines in those files where \
word appears:
\begin{verbatim}
~/hacker-within/bootcamp/monday% grep "grep" notes.tex
~/haystack> grep -r "needle" *
[1]  + Suspended                     grep -r needle *
grep -r needle *
\subsection{More file inspection: \texttt{head/tail, grep}}
the contents of a file is \texttt{grep} (the command \
text-search tool. We'll talk way more about \texttt{grep} and \
for now, simply notes that \texttt{grep ``word'' files} searches \
\end{verbatim}
Note that each line contains the search term somewhere.

\subsection{Printing (\texttt{lpr})}
Printing plain text files in Unix is easy; \texttt{lpr filename} prints the file using the default printer. Printing exotic file types to specific printers gets a bit more complex. If you use a graphical program (e.g., \texttt{evince}, \texttt{xpdf}, \texttt{eog}, \texttt{ooffice}) to view your file, it's probably best to use that program's built-in print dialog command.

\subsection{Exercise: Organizing a mess of files}
As a summative exercise for today, we're going to try to bring some order to a chaotic bunch of files. The \texttt{bootcamp/monday/files} directory contains an unsorted collection of files that should be sorted into new directories that you create. Try to use as many of the commands and programs that we've discussed to day as possible, and remember that most programmers are lazy, so if you're frustrated by how long a tedious task is taking, you can pretty safely assume that someone's probably created a faster way to do it. Consult \texttt{man} pages (and Google and \textsc{WikipediA} for that matter) early and often. \medskip

Your mission, should you choose to accept it, is the following:
\begin{enumerate}
\item Create a directory in your home directory called \texttt{data} and move all of the \texttt{.csv} (Comma-Separated Values) files there. Because they've been named poorly, you should also take a look at the first few lines of each and rename them in more descriptive terms.
\item Create a directory in your home directory called \texttt{public\_html} and move any \texttt{.html} files and any \texttt{.jpg} files they refer to into that directory. Make sure the file permissions are set so that anyone can read the files and directory but not write to it.
\item Move all the \texttt{.txt} files of \textsc{WikipediA} articles into a new directory called \texttt{articles/}. \textbf{Bonus points: } If you have time, consult \mbox{\texttt{man cat}} and \mbox{\texttt{man wc}} to try to figure out a way turn them into one long file and do a word- and line-count on that file. No copying/pasting allowed!
\item Move all other files to a directory called \verb|~/personal/| and set the permissions so that the directory can't be visited or read by others. \textbf{Bonus points: } Try archiving and compressing the \texttt{.jpg} files with \texttt{tar} and \texttt{zip} or \texttt{gzip} or converting them to different image formats. Remember, there are command-line utilities for doing all sorts of conversion. For instance, you could use \texttt{jpeg2ps} and \texttt{ps2pdf} to convert to \texttt{.jpg}s to PDF-format. You could also check out \texttt{convert}, which is like a command-line Photoshop.
\end{enumerate}
\end{document}
